package com.example.demo.service.impl;

import com.example.demo.dao.Activity;
import com.example.demo.dao.ActivityExample;
import com.example.demo.dao.CategoryExample;
import com.example.demo.mapper.ActivityMapper;
import com.example.demo.service.activityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class activityServiceImpl implements activityService {
    @Autowired
    private ActivityMapper activityMapper;



    @Override
    public Activity findActivity(Integer id) {
       Activity activity =activityMapper.selectByPrimaryKey(id);
        return activity;
    }

    @Override
    public int  saveActivity(Activity activity) {
     return   activityMapper.insertSelective(activity);
    }

    //分页查询
    @Override
    public List<Activity> listActivity(String keyword) {
        keyword = "%"+keyword+"%";
        ActivityExample activityExample = new ActivityExample();
        activityExample.or().andActivitynameLike(keyword);
        List<Activity> activities = activityMapper.selectByExample(activityExample);
        return activities;
    }
    //删除活动
    @Override
    public int delectActivity(Integer id) {
        return  activityMapper.deleteByPrimaryKey(id);
    }
    //  批量删除
    @Override
    public int multiDel(String id) {
        ActivityExample activityExample = new ActivityExample();
        List<String> list = Arrays.asList(id.split(","));
        List<Integer> ilist = list.stream().map(Integer::parseInt).collect(Collectors.toList());
        activityExample.or().andActivityidIn(ilist);
        return activityMapper.deleteByExample(activityExample);
    }
//修改活动
    @Override
    public int editActivity(Activity activity) {
        return  activityMapper.updateByPrimaryKeySelective(activity);
    }

    @Override
    public Activity findactivitys(Integer activityid) {
        return activityMapper.findByActivityId(activityid);
    }

    @Override
    public List<Activity> getAllActivity(ActivityExample activityExample) {
        return activityMapper.selectByExample(activityExample);
    }


}
